package com.qq.Servlet.Book;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//center过滤器的注解
@WebServlet("/center/book/service")
public class BookServiceServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //防止乱码
        resp.setContentType("text/html;charset=utf-8");
        String option = req.getParameter("option");
        //这里加上resp就可以在下面方法中用resp.getWriter().write("我是z");进行输出了
        //在url上输入http://localhost:8080/testweb/book/service?option=s进行对应方法访问，这里是调用s方法
        if (option.equals("s"))s(resp);
        else if (option.equals("y"))y(resp);
        else if (option.equals("z"))z(resp);
    }

    private void z(HttpServletResponse resp)throws IOException {
        //是在浏览器中输出的
        resp.getWriter().write("我是z");
    }

    private void y(HttpServletResponse resp)throws IOException {
        //是在浏览器中输出的
        resp.getWriter().write("我是y");
    }

    private void s(HttpServletResponse resp)throws IOException {
        //是在浏览器中输出的
        resp.getWriter().write("我是s");
    }
}